#include "RemoteControl.hpp"

void Test1()
{
    // 创建远程遥控器
    RemoteControl *Remote = new RemoteControl();
    // 创建卧室灯
    LivingRoomLight livingLight;
    // 创建卧室灯开灯命令
    LightOnCommand lightOn;
    // 创建卧室灯关灯命令
    LightOffCommand lightOff;
    // 设置卧室灯
    lightOn.SetLight(&livingLight);
    lightOff.SetLight(&livingLight);

    // 创建外门
    OutDoor outdoor;
    // 创建外门开门命令
    DoorOpenCommand doorOpen;
    // 创建外门关门命令
    DoorCloseCommand doorClose;
    // 设置外门
    doorOpen.SetDoor(&outdoor);
    doorClose.SetDoor(&outdoor);

    // 创建风扇
    CeilingFan cFan;
    // 创建高档位命令
    CeilingFanHighCommand fanHigh;
    fanHigh.SetFan(&cFan);
    // 创建中档位命令
    CeilingFanMediumCommand fanMedium;
    fanMedium.SetFan(&cFan);
    // 创建低档位命令
    CeilingFanLowCommand fanLow;
    fanLow.SetFan(&cFan);
    // 创建关闭命令
    CeilingFanOffCommand fanOff;
    fanOff.SetFan(&cFan);

    // 设置风扇
    Remote->SetCommand(3, &fanHigh, &fanOff);
    Remote->SetCommand(4, &fanMedium);
    Remote->SetCommand(5, &fanLow);

    // 向远程遥控器中添加命令
    Remote->SetCommand(1, &lightOn, &lightOff);
    Remote->SetCommand(2, &doorOpen, &doorClose);
    // Remote->On();
    // Remote->Off();
    // Remote->OnButtonWasPushed(1);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(2);
    // Remote->UndoButonWasPushed();

    // Remote->OffButtonWasPushed(1);
    // Remote->UndoButonWasPushed();

    // Remote->OffButtonWasPushed(2);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(3);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(4);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(5);
    // Remote->UndoButonWasPushed();

    Remote->OnButtonWasPushed(3);
    Remote->OnButtonWasPushed(4);
    Remote->OnButtonWasPushed(5);
    Remote->UndoButonWasPushed();
    // Remote->UndoButonWasPushed();
    // Remote->UndoButonWasPushed();
    delete Remote;
}

// 测试stereo
void Test2()
{
    // 创建远程遥控器
    RemoteControl *Remote = new RemoteControl(20); // 设置按键数量
    // 创建Stereo
    Stereo stereo;
    // 创建Stereo命令
    StereoOnCommand stereoOn;
    StereoOffCommand stereoOff;
    StereoDvdCommand stereoDvd;
    StereoRadioCommand stereoRadio;
    StereoVolumCommand stereoVolum;
    StereoCdCommand stereoCd;
    // 初始化Stereo命令
    stereoOn.SetStereo(&stereo);
    stereoOff.SetStereo(&stereo);
    stereoDvd.SetStereo(&stereo);
    stereoRadio.SetStereo(&stereo);
    stereoVolum.SetStereo(&stereo);
    stereoCd.SetStereo(&stereo);

    // 设置远程控制
    Remote->SetCommand(1, &stereoOn, &stereoOff);
    Remote->SetCommand(2, &stereoDvd);
    Remote->SetCommand(3, &stereoRadio);
    Remote->SetCommand(4, &stereoVolum);
    Remote->SetCommand(5, &stereoCd);

    // 启动
    // Remote->OnButtonWasPushed(1);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(2);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(3);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(4);
    // Remote->UndoButonWasPushed();

    // Remote->OnButtonWasPushed(5);
    // Remote->UndoButonWasPushed();

    // Remote->OffButtonWasPushed(1);
    // Remote->UndoButonWasPushed();

    // 撤销没问题
    Remote->OnButtonWasPushed(1);
    Remote->OnButtonWasPushed(2);
    Remote->OnButtonWasPushed(3);
    Remote->UndoButonWasPushed();
    Remote->UndoButonWasPushed();
    Remote->UndoButonWasPushed();

    // 释放空间
    delete Remote;
}

// 测试Party按钮
void Test3()
{
    // 创建远程遥控器
    RemoteControl *Remote = new RemoteControl(20); // 设置按键数量

    // 创建设备
    LivingRoomLight livingLight;
    OutDoor outDoor;
    CeilingFan ceilingFan;
    Stereo stereo;

    // 创建命令
    LightOnCommand lightOnCommand;
    LightOffCommand lightOffCommand;
    DoorOpenCommand doorOpenCommand;
    DoorCloseCommand doorCloseCommand;
    CeilingFanHighCommand fanHighCommand;
    CeilingFanOffCommand fanOffCommand;
    StereoOnCommand stereoOnCommand;
    StereoCdCommand setCdCommand;
    StereoDvdCommand setDvdCommand;
    StereoRadioCommand setRadioCommand;
    StereoVolumCommand setVolumCommand;
    StereoOffCommand stereoOffCommand;

    // 初始化命令
    lightOnCommand.SetLight(&livingLight);
    lightOffCommand.SetLight(&livingLight);
    doorOpenCommand.SetDoor(&outDoor);
    doorCloseCommand.SetDoor(&outDoor);
    fanHighCommand.SetFan(&ceilingFan);
    fanOffCommand.SetFan(&ceilingFan);
    stereoOnCommand.SetStereo(&stereo);
    stereoOffCommand.SetStereo(&stereo);
    setCdCommand.SetStereo(&stereo);
    setDvdCommand.SetStereo(&stereo);
    setRadioCommand.SetStereo(&stereo);
    setVolumCommand.SetStereo(&stereo);

    // 创建Party命令集
    MacroCommand macroOn;  // party启动命令集
    MacroCommand macroOff; // party关闭命令集

    // 创建命令vector
    std::vector<Command *> partyOn = {&lightOnCommand, &doorOpenCommand, &fanHighCommand,
                                      &stereoOnCommand, &setCdCommand, &setDvdCommand,
                                      &setRadioCommand, &setVolumCommand};

    std::vector<Command *> partyOff = {&lightOffCommand, &doorCloseCommand, &fanOffCommand,
                                       &stereoOffCommand};

    // 初始化命令集
    macroOn.SetPartyCommand(partyOn.size(), partyOn);
    macroOff.SetPartyCommand(partyOff.size(), partyOff);

    // 设置远程控制
    Remote->SetCommand(1, &macroOn, &macroOff);

    // 启动Party
    Remote->OnButtonWasPushed(1);
    // std::cout << ceilingFan.GetSpeed() << std::endl;
    std::cout << std::endl;

    // 撤销
    // Remote->UndoButonWasPushed();
    // std::cout << std::endl;

    // 关闭Party
    Remote->OffButtonWasPushed(1);
    // sstd::cout << ceilingFan.GetSpeed() << std::endl;
    std::cout << std::endl;

    // 撤销(Undo中的撤销设计有点问题)
    Remote->UndoButonWasPushed();
    // std::cout << ceilingFan.GetSpeed() << std::endl;
    std::cout << std::endl;

    delete Remote;
}

int main()
{
    // Test1();
    // Test2();
    Test3();
    return 0;
}